package day06;
import java.util.Arrays;
public class Test {
    public static void main(String[] args) {
            int arr1 = geyMaxOfArray(5,8);
            sayhi();
            sayHello("张三");
            sayage("张三",66);
            double a = getNum();
            System.out.println(a);
            int b = puls(5,6);
            System.out.println(b);
            int m = 50,n = 60;
            int c = add(m,n);
            System.out.println(c);
            int [] d = testArray(5,10);
            System.out.println(d.length);
            for(int i = 0;i<d.length;i++) {
                System.out.println(d[i]);
            }
            int [] e = testArray(3,100);
                for(int j = 0;j<e.length;j++){
                    System.out.println(e[j]);
                }
        System.out.println("-------------------------------");
            //1. MaxOfArray求数组元素最大值并放在最后一个元素的下一个位置
            //   要求：声明整型数组并填充随机数据，找到最大值，将数组扩容并将最大值放末尾
             int [] arr = new int [10];
                int max = arr [0];
                for(int i = 0;i< arr.length;i++){
                    arr [i] = (int) (Math.random()*100);
                    if(arr[i]>max){
                        max = arr[i];
                    }
                    System.out.println(arr[i]);
                }
                    System.out.println("最大值为："+max);
                    arr = Arrays.copyOf(arr,arr.length+1);
                        arr [arr.length-1] = max;

    }
    //无参无返回值
    public static void sayhi(){
        System.out.println("hi!");
    }
    //有参无返回值
    public static void sayHello(String name){
        System.out.println("Hi!my name is"+name+".");
    }
    public static void sayage(String name,int age){
        System.out.println("Hi!my name is"+name+",I'm"+age+"years old.");
    }
    //无参有返回值
    public static double getNum(){
        double a = 0.8;
        return a;
    }
    //有参有返回值
    public static int puls(int num1,int num2){
        int num = num1+num2;
        return num;
    }
    public static int add(int a,int b){
        int add = a+b;
        return add;
    }
    public static int [] testArray(int length,int quantity){
        int [] arr = new int[length];
        for(int i = 0;i<arr.length;i++){
            arr [i] = (int)(Math.random()*quantity);
        }
        return arr;
    }
    public static int geyMaxOfArray(int len,int quantity){
            int [] arr = new int[len];
            for(int i = 0;i<arr.length;i++){
                arr[i] = (int)(Math.random()*quantity);
                System.out.println(arr [i]);
            }
            int max = arr[0];
            for(int i = 0;i<arr.length;i++){
                if(arr[i]>max){
                    max = arr[i];
                }
            }
        System.out.println("最大值为："+max);
            return max;
    }
}
